home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / Dev / mamesrc / src / amiga / amiga.c next >
Encoding:
C/C++ Source or Header  |  1999-12-03  |  50.1 KB  |  2,298 lines

  1. /**************************************************************************
  2.  *
  3.  * Copyright (C) 1999 Mats Eirik Hansen (mats.hansen@triumph.no)
  4.  *
  5.  * $Id: amiga.c,v 1.1 1999/04/28 18:50:15 meh Exp meh $
  6.  *
  7.  * $Log: amiga.c,v $
  8.  * Revision 1.1  1999/04/28 18:50:15  meh
  9.  * Initial revision
  10.  *
  11.  *
  12.  *************************************************************************/
  13.  
  14. #include <stdio.h>
  15.  
  16. #include <exec/types.h>
  17. #include <exec/memory.h>
  18. #include <dos/dos.h>
  19. #include <dos/dosextens.h>
  20. #include <cybergraphx/cybergraphics.h>
  21.  
  22. #include "mame.h"
  23. #include "driver.h"
  24. #include "osdepend.h"
  25.  
  26. #include "main.h"
  27. #include "config.h"
  28. #include "file.h"
  29. #include "audio.h"
  30.  
  31. #define INTELULONG(i) (((i)<<24)|((i)>>24)|(((i)<<8)&0x00ff0000)|(((i)>>8)&0x0000ff00))
  32.  
  33. #ifdef POWERUP
  34. extern LONG FrameSkip;
  35. extern LONG FPS;
  36.  
  37. #define VGetFrameSkip(video) FrameSkip
  38. #define VGetFPS(video)       FPS
  39.  
  40. #define VSetFrameSkip(video,frameskip)
  41. #define VSetLimitSpeed(video,limitspeed)
  42. #endif
  43.  
  44. struct osd_bitmap *BitMap;
  45. LONG ClearBitMap;
  46.  
  47. static LONG  UserInterface;
  48.  
  49. extern FILE *errorlog;
  50. extern void *record;
  51. extern void *playback;
  52.  
  53. static UBYTE Palette[256][3];
  54.  
  55. static int MasterVolume;
  56. static int Attenuation;
  57.  
  58. static int FrameCounter;
  59. static const int NoFrameSkipCount = 10;
  60.  
  61. static char ROMZipName[256];
  62. static char SampleZipName[256];
  63.  
  64. static int  ShowFPS;
  65.  
  66. static int on_screen_display_timer;
  67.  
  68. char *DirtyLines[6];
  69.  
  70. int frameskip;
  71. int autoframeskip = 0;
  72. int throttle;
  73. int video_sync  = 0;
  74. unsigned char No_FM   = 1;
  75.  
  76. static int input_update_counter = 0;
  77.  
  78. extern int antialias;
  79. extern int beam;
  80. extern int flicker;
  81. extern int translucency;
  82.  
  83. int load_zipped_file(const char *zipfile, const char *filename, unsigned char **buf, int *length);
  84. unsigned int crc32(unsigned int crc, const unsigned char *buf, unsigned int len);
  85.  
  86. void StartGame(void)
  87. {
  88. #ifdef MESS
  89.   int i;
  90. #endif
  91.  
  92.   throttle = 1;
  93.  
  94.   options.errorlog = NULL;
  95.  
  96. /*  if(Options[OPT_RECORD])
  97.     options.record = osd_fopen( drivers[Options[OPT_GAME]]->name, (const char *) Options[OPT_RECORD],
  98.                   OSD_FILETYPE_INPUTLOG, 1);
  99.   else*/
  100.     options.record = NULL;
  101.  
  102. /*  if(Options[OPT_PLAYBACK])
  103.     options.playback = osd_fopen( drivers[Options[OPT_GAME]]->name, (const char *) Options[OPT_PLAYBACK],
  104.                     OSD_FILETYPE_INPUTLOG, 0);
  105.   else*/
  106.     options.playback = NULL;
  107.  
  108.   if(Config[CFG_SOUND] == CFGS_NO)
  109.     options.samplerate  = 0;
  110.   else
  111.     options.samplerate  = 22000;
  112.  
  113.   Machine->sample_rate = options.samplerate;
  114.  
  115.   options.samplebits = 8;
  116.   options.mame_debug = 0;
  117.   options.cheat      = 1;
  118.   options.norotate   = 0;
  119.   options.ror        = (Config[CFG_ROTATION] == CFGR_RIGHT);
  120.   options.rol        = (Config[CFG_ROTATION] == CFGR_RIGHT);
  121.   options.flipx      = Config[CFG_FLIPX];
  122.   options.flipy      = Config[CFG_FLIPY];
  123.  
  124.   frameskip = Config[CFG_FRAMESKIP];
  125.  
  126.   antialias    = Config[CFG_ANTIALIASING];
  127.   translucency = Config[CFG_TRANSLUCENCY];
  128.  
  129.   beam = Config[CFG_BEAMWIDTH] * 0x00010000;
  130.   if(beam < 0x00010000)
  131.     beam = 0x00010000;
  132.   if(beam > 0x00100000)
  133.     beam = 0x00100000;
  134.  
  135.   flicker = (int)(Config[CFG_VECTORFLICKER] * 2.55);
  136.   if(flicker < 0)
  137.     flicker = 0;
  138.   if(flicker > 255)
  139.     flicker = 255;
  140.  
  141. #ifdef MESS
  142.   for(i = 0; i < MAX_ROM; i++)
  143.   {
  144.     options.rom_name[i][0] = 0;
  145.  
  146.     if((i == 0) && Config[CFG_ROM])
  147.       strcpy(options.rom_name[0], (char *) Config[CFG_ROM]);
  148.   }
  149.  
  150.   for(i = 0; i < MAX_FLOPPY; i++)
  151.     options.floppy_name[i][0] = 0;
  152.  
  153.   for(i = 0; i < MAX_HARD; i++)
  154.     options.hard_name[i][0] = 0;
  155.  
  156.   for(i = 0; i < MAX_CASSETTE; i++)
  157.     options.cassette_name[i][0] = 0;
  158. #endif
  159.  
  160.   /* Clear the zip filename caches. */
  161.  
  162.   ROMZipName[0]    = 0;
  163.   SampleZipName[0] = 0;
  164.   ShowFPS          = 0;
  165.  
  166.   FrameCounter = 0;
  167.  
  168.   osd_set_mastervolume(0);
  169.  
  170.   run_game(Config[CFG_DRIVER]);
  171.  
  172.   if(options.playback)
  173.     osd_fclose(options.playback);
  174.   
  175.   if(options.record)
  176.     osd_fclose(options.record);
  177. }
  178.  
  179. int osd_init()
  180. {
  181.   return(0);
  182. }
  183.  
  184. void osd_exit()
  185. {
  186. }
  187.  
  188. struct osd_bitmap *osd_new_bitmap(int width, int height, int depth)
  189. {
  190.   struct osd_bitmap *bitmap;
  191.   unsigned char   *line;
  192.   LONG        safety;
  193.   LONG        i, w;
  194.  
  195.   TRACE_ENTER("osd_new_bitmap");
  196.  
  197.   if(Machine->orientation & ORIENTATION_SWAP_XY)
  198.   {
  199.     w   = width;
  200.     width = height;
  201.     height  = w;
  202.   }
  203.  
  204.   if(width > 32)
  205.     safety = 8;
  206.   else
  207.     safety = 0;
  208.  
  209.   if(depth != 16)
  210.   {
  211.     depth = 8;
  212.     w = ((width + 2 * safety + 3) >> 2) << 2;
  213.   }
  214.   else
  215.     w = ((2 * (width + 2 * safety) + 3) >> 2) << 2;
  216.  
  217.   bitmap = (struct osd_bitmap *) calloc(  sizeof(struct osd_bitmap)
  218.                       + height*sizeof(unsigned char *)
  219.                       + w*(height+2*safety)*sizeof(unsigned char), 1);
  220.  
  221.   if(bitmap)
  222.   {
  223.     bitmap->width    = width;
  224.     bitmap->height   = height;
  225.     bitmap->depth    = depth;
  226.     bitmap->_private = (void *) w;
  227.     bitmap->line     = (unsigned char **) &bitmap[1]; 
  228.  
  229.     line = ((unsigned char *) &bitmap->line[height]) + safety * w;
  230.  
  231.     for(i = 0; i < height; i++)
  232.     {
  233.       bitmap->line[i] = line;
  234.       line += w*sizeof(unsigned char);
  235.     }
  236.   }
  237.  
  238.   TRACE_LEAVE("osd_new_bitmap");
  239.  
  240.   return(bitmap);
  241. }
  242.  
  243. void osd_free_bitmap(struct osd_bitmap *bitmap)
  244. {
  245.   TRACE_ENTER("osd_free_bitmap");
  246.  
  247.   if(bitmap)
  248.     free(bitmap);
  249.  
  250.   TRACE_LEAVE("osd_free_bitmap");
  251. }
  252.  
  253. void osd_clearbitmap(struct osd_bitmap *bitmap)
  254. {
  255.   int i;
  256.  
  257.   TRACE_ENTER("osd_clearbitmap");
  258.  
  259.   for (i = 0;i < bitmap->height;i++)
  260.     memset(bitmap->line[i],0,bitmap->width);
  261.  
  262.   if(bitmap == BitMap)
  263.   {
  264. #ifdef POWERUP
  265.     ClearBitMap = (ClearBitMap + 1) & 1;
  266. #endif
  267.     if(DirtyLines[0])
  268.       memset(DirtyLines[0], 1, BitMap->height);
  269.   }
  270.  
  271.   TRACE_LEAVE("osd_clearbitmap");
  272. }
  273.  
  274. void osd_mark_dirty(int x1, int y1, int x2, int y2, int ui)
  275. {
  276.   if(DirtyLines[0] && (y1 < BitMap->height) && (y2 >= 0))
  277.   {
  278.     if(y1 < 0)
  279.       y1 = 0;
  280.     if(y2 >= BitMap->height)
  281.       y2 = BitMap->height-1;
  282.     memset(&DirtyLines[0][y1], 1, y2 - y1 + 1);
  283.   }
  284.  
  285.   if(ui)
  286.     UserInterface = TRUE;
  287. }
  288.  
  289. /* palette is an array of 'totalcolors' R,G,B triplets. The function returns */
  290. /* in *pens the pen values corresponding to the requested colors. */
  291. /* If 'totalcolors' is 32768, 'palette' is ignored and the *pens array is filled */
  292. /* with pen values corresponding to a 5-5-5 15-bit palette */
  293.  
  294. static inline short makecol(int r, int g, int b)
  295. {
  296.   switch(PixelArray[0]->PixelFormat)
  297.   {
  298.     case PIXFMT_RGB15:
  299.       return((r&0xf8)<<7)|((g&0xf8)<<2)|(b>>3);
  300.       break;
  301.  
  302.     case PIXFMT_BGR15:
  303.       return((b&0xf8)<<7)|((g&0xf8)<<2)|(r>>3);
  304.       break;
  305.  
  306.     case PIXFMT_RGB15PC:
  307.       return((r&0xf8)>>1)|(g>>6)|((g&0x38)<<10)|((b&0xf8)<<5);
  308.       break;
  309.  
  310.     case PIXFMT_BGR15PC:
  311.       return((b&0xf8)>>1)|(g>>6)|((g&0x38)<<10)|((r&0xf8)<<5);
  312.       break;
  313.  
  314.     case PIXFMT_BGR16:
  315.       return((b&0xf8)<<8)|((g&0xfc)<<3)|(r>>3);
  316.       break;
  317.  
  318.     case PIXFMT_RGB16PC:
  319.       return(r&0xf8)|(g>>5)|((g&0x1c)<<11)|((b&0xf8)<<5);
  320.       break;
  321.  
  322.     case PIXFMT_BGR16PC:
  323.       return(b&0xf8)|(g>>5)|((g&0x1c)<<11)|((r&0xf8)<<5);
  324.       break;
  325.  
  326.     case PIXFMT_RGB16:
  327.     default:
  328.       return((r&0xf8)<<8)|((g&0xfc)<<3)|(b>>3);
  329.       break;
  330.   }
  331. }
  332.  
  333. void osd_allocate_colors(unsigned int total_colors,const unsigned char *palette,unsigned short *pens)
  334. {
  335.   TRACE_ENTER("osd_allocate_colors");
  336.  
  337.   if(total_colors == 32768)
  338.   {
  339.     int r,g,b;
  340.  
  341.     for (r = 0; r < 32; r++)
  342.     {
  343.       for (g = 0; g < 32; g++)
  344.       {
  345.         for (b = 0; b < 32; b++)
  346.         {
  347.                     *pens++ = makecol(r<<3,g<<3,b<<3);
  348.         }
  349.       }
  350.     }
  351.  
  352.         Machine->uifont->colortable[0] = makecol(0x00,0x00,0x00);
  353.         Machine->uifont->colortable[1] = makecol(0xff,0xff,0xff);
  354.         Machine->uifont->colortable[2] = makecol(0xff,0xff,0xff);
  355.         Machine->uifont->colortable[3] = makecol(0x00,0x00,0x00);
  356.   }
  357.   else
  358.   {
  359.     int i;
  360.     int best_black;
  361.     int best_white;
  362.     int best_black_score;
  363.     int best_white_score;
  364.  
  365.     best_black       = 0;
  366.     best_white       = 0;
  367.     best_black_score = 3*255*255;
  368.     best_white_score = 0;
  369.  
  370.     for(i = 0; i < total_colors; i++)
  371.     {
  372.       int r,g,b,score;
  373.  
  374.       pens[i] = i;
  375.  
  376.       r = palette[3*i];
  377.       g = palette[3*i+1];
  378.       b = palette[3*i+2];
  379.  
  380.       score = r*r + g*g + b*b;
  381.  
  382.       if(score < best_black_score)
  383.       {
  384.         best_black       = i;
  385.         best_black_score = score;
  386.       }
  387.  
  388.       if(score > best_white_score)
  389.       {
  390.         best_white       = i;
  391.         best_white_score = score;
  392.       }
  393.     }
  394.  
  395.     Machine->uifont->colortable[0] = pens[best_black];
  396.     Machine->uifont->colortable[1] = pens[best_white];
  397.     Machine->uifont->colortable[2] = pens[best_white];
  398.     Machine->uifont->colortable[3] = pens[best_black];
  399.  
  400.     if(DirectArray)
  401.     {
  402.       for(i = 0; i < total_colors; i++)
  403.       {
  404.         DirectArray->Palette[pens[i]][1]  = palette[3*i];
  405.         DirectArray->Palette[pens[i]][2]  = palette[3*i+1];
  406.         DirectArray->Palette[pens[i]][3]  = palette[3*i+2];
  407.  
  408.         Palette[pens[i]][0] = palette[3*i];
  409.         Palette[pens[i]][1] = palette[3*i+1];
  410.         Palette[pens[i]][2] = palette[3*i+2];
  411.       }
  412.     }
  413.     else
  414.     {
  415.       for(i = 0; i < total_colors; i++)
  416.       {
  417.         PixelArray[0]->Palette[pens[i]][1]  = palette[3*i];
  418.         PixelArray[0]->Palette[pens[i]][2]  = palette[3*i+1];
  419.         PixelArray[0]->Palette[pens[i]][3]  = palette[3*i+2];
  420.  
  421.         Palette[pens[i]][0] = palette[3*i];
  422.         Palette[pens[i]][1] = palette[3*i+1];
  423.         Palette[pens[i]][2] = palette[3*i+2];
  424.       }
  425.     }
  426.   }
  427.  
  428.   TRACE_LEAVE("osd_allocate_colors");
  429. }
  430.  
  431. struct osd_bitmap *osd_create_display(int width, int height, int attributes)
  432. {
  433.   unsigned char *line;
  434.   
  435.   LONG left, top, right, bottom;
  436.   LONG i, t;
  437.  
  438.   TRACE_ENTER("osd_create_display");
  439.  
  440.   if(Machine->orientation & ORIENTATION_SWAP_XY)
  441.   {
  442.     t      = width;
  443.     width  = height;
  444.     height = t;
  445.     
  446.     left   = Machine->drv->visible_area.min_y;
  447.     top    = Machine->drv->visible_area.min_x;
  448.     right  = Machine->drv->visible_area.max_y;
  449.     bottom = Machine->drv->visible_area.max_x;
  450.   }
  451.   else
  452.   {
  453.     left   = Machine->drv->visible_area.min_x;
  454.     top    = Machine->drv->visible_area.min_y;
  455.     right  = Machine->drv->visible_area.max_x;
  456.     bottom = Machine->drv->visible_area.max_y;
  457.   }
  458.  
  459.   if(attributes & VIDEO_TYPE_VECTOR)
  460.   {
  461.     if(Config[CFG_WIDTH] > width)
  462.       width = Config[CFG_WIDTH];
  463.  
  464.     if(Config[CFG_HEIGHT] > height)
  465.       height = Config[CFG_HEIGHT];
  466.       
  467.     left   = 0;
  468.     top    = 0;
  469.     right  = width - 1;
  470.     bottom = height - 1;
  471.   }
  472.   else
  473.   {
  474.     if(Machine->orientation & ORIENTATION_FLIP_X)
  475.     {
  476.       t     = width - left - 1;
  477.       left  = width - right - 1;
  478.       right = t;
  479.     }
  480.     
  481.     if(Machine->orientation & ORIENTATION_FLIP_Y)
  482.     {
  483.       t      = height - top - 1;
  484.       top    = height - bottom - 1;
  485.       bottom = t;
  486.     }
  487.   }
  488.  
  489.   Machine->uiwidth  = right - left + 1;
  490.   Machine->uiheight = bottom - top + 1;
  491.   Machine->uixmin   = left;
  492.   Machine->uiymin   = top;
  493.  
  494.   if(VideoOpen(width, height, left, top, right, bottom, attributes & VIDEO_SUPPORTS_DIRTY))
  495.   {
  496.     DirtyLines[0] = NULL;
  497.  
  498.     if(DirectArray)
  499.     {
  500.       BitMap = osd_new_bitmap(width, height, 8);
  501.       
  502.       if((Config[CFG_DIRECTMODE] == CFGDM_COPY) && Config[CFG_DIRTYLINES] && !Config[CFG_BUFFERING])
  503.       {
  504.         DirtyLines[0] = calloc(2 * (1 + Config[CFG_BUFFERING]) * height, 1);
  505.       
  506.         if(DirtyLines[0])
  507.         {
  508.           for(i = 0; i < (2 * (Config[CFG_BUFFERING] + 1)); i++)
  509.             DirtyLines[i+1] = DirtyLines[i] + height;
  510.         }
  511.       }
  512.     }
  513.     else
  514.     {
  515.       if(PixelArray[0]->DirtyLines)
  516.       {
  517.         DirtyLines[0] = calloc(2 * (1 + Config[CFG_BUFFERING]) * height, 1);
  518.       
  519.         if(DirtyLines[0])
  520.         {
  521.           for(i = 0; i < (2 * (Config[CFG_BUFFERING] + 1)); i++)
  522.             DirtyLines[i+1] = DirtyLines[i] + height;
  523.         }
  524.       }
  525. #ifdef POWERUP
  526.       BitMap  = (struct osd_bitmap *) malloc( sizeof(struct osd_bitmap) + 2*height*sizeof(unsigned char *));
  527. #else
  528.       BitMap  = (struct osd_bitmap *) malloc( sizeof(struct osd_bitmap) + height*sizeof(unsigned char *));
  529. #endif
  530.     }
  531.     
  532.     if(BitMap)
  533.     {
  534.       ClearBitMap = 0;
  535.  
  536.       if(DirectArray)
  537.       {     
  538.         if(Config[CFG_DIRECTMODE] == CFGDM_DRAW)
  539.         {
  540.           line = DirectArray->Pixels + 8 + (8 * DirectArray->BytesPerRow);
  541.  
  542.           for(i = 0; i < height; i++)
  543.           {
  544.             BitMap->line[i] = line;
  545.  
  546.             line += DirectArray->BytesPerRow;
  547.           }
  548.         }
  549.       }
  550.       else
  551.       {
  552.         BitMap->width  = width;
  553.         BitMap->height = height;
  554.         BitMap->line   = (unsigned char **) &BitMap[1];
  555.  
  556.         if(PixelArray[0]->PixelFormat)
  557.           BitMap->depth = 16;
  558.         else
  559.           BitMap->depth = 8;
  560.   
  561.  
  562.         line = (unsigned char *) VGetPixelArrayPointAddr(PixelArray[0], 8, 8);
  563.  
  564.         for(i = 0; i < height; i++)
  565.         {
  566.           BitMap->line[i] = line;
  567.  
  568.           line += PixelArray[0]->BytesPerRow;
  569.         }
  570. #ifdef POWERUP
  571.         line  = (unsigned char *) VGetPixelArrayPointAddr(PixelArray[1], 8, 8);
  572.  
  573.         for(; i < (height << 1); i++)
  574.         {
  575.           BitMap->line[i] = line;
  576.  
  577.           line += PixelArray[1]->BytesPerRow;
  578.         }
  579.  
  580.         for(i = 0; i < 256; i++)
  581.         {
  582.           PixelArray[1]->Palette[i][0]  = 0;
  583.           PixelArray[1]->Palette[i][1]  = 0;
  584.           PixelArray[1]->Palette[i][2]  = 0;
  585.           PixelArray[1]->Palette[i][3]  = 0;
  586.         }
  587. #endif
  588.         for(i = 0; i < 256; i++)
  589.         {
  590.           PixelArray[0]->Palette[i][0]  = 1;
  591.           PixelArray[0]->Palette[i][1]  = 0;
  592.           PixelArray[0]->Palette[i][2]  = 0;
  593.           PixelArray[0]->Palette[i][3]  = 0;
  594.         }
  595.       }
  596.  
  597.       TRACE_LEAVE("osd_create_display");
  598.  
  599.       return(BitMap);
  600.     }
  601.  
  602.     VideoClose();
  603.   }
  604.  
  605.   TRACE_LEAVE("osd_create_display");
  606.  
  607.   return(NULL);
  608. }
  609.  
  610. void osd_close_display(void)
  611. {
  612.   LONG i;
  613.  
  614.   TRACE_ENTER("osd_close_display");
  615.   
  616.   if(DirtyLines[0])
  617.   {
  618.     for(i = 1; i < (2 * (Config[CFG_BUFFERING] + 1)); i++)
  619.     {
  620.       if(DirtyLines[0] > DirtyLines[i])
  621.         DirtyLines[0] = DirtyLines[i];
  622.     }
  623.   
  624.     free(DirtyLines[0]);
  625.   }
  626.  
  627.   if(BitMap)
  628.     free(BitMap);
  629.  
  630.   TRACE_LEAVE("osd_close_display");
  631.  
  632.   VideoClose();
  633. }
  634.  
  635. void osd_update_video_and_audio(void)
  636. {
  637.   unsigned char *line;
  638.   int       trueorientation;
  639.   int       fps;
  640.   LONG      i, j, w, h, l;
  641.   ULONG     bpr;
  642.   ULONG     mod;
  643.   ULONG     srcmod;
  644.   ULONG     *src;
  645.   ULONG     *pix;
  646.   UBYTE     **lines;
  647.   UBYTE     *dst;
  648.   UBYTE     *new, *new2, *new3;
  649.   UBYTE     *old, *old2, *old3;
  650.   char      buf[30];
  651.  
  652.   static int showfpstemp;
  653.   int need_to_clear_bitmap = 0;
  654.  
  655.   TRACE_ENTER("osd_update_video_and_audio");
  656.  
  657.   /* Do not skip frames on the initial information screens. */
  658.  
  659.   if(FrameCounter >= NoFrameSkipCount)
  660.   {
  661.     if(FrameCounter < (NoFrameSkipCount + frameskip))
  662.     {
  663.       FrameCounter++;
  664.       
  665.       return;
  666.     }
  667.  
  668.     FrameCounter = NoFrameSkipCount;
  669.   }
  670.   else
  671.     FrameCounter++;
  672.  
  673.   if(ChannelArray[0])
  674.   {
  675. #ifdef POWERUP
  676.     if(!ChannelArray[1])
  677.       return;
  678. #endif
  679.     ASetChannelFrame(ChannelArray[CurrentArray]);
  680.   }
  681.  
  682.   if(osd_key_pressed_memory(OSD_KEY_THROTTLE))
  683.     throttle ^= 1;
  684.  
  685.   if(osd_key_pressed_memory(OSD_KEY_FRAMESKIP_INC))
  686.   {
  687.     frameskip   = (frameskip + 1) % 4;
  688.     showfpstemp = 50;
  689.   }
  690.  
  691.   if(osd_key_pressed_memory(OSD_KEY_SHOW_FPS))
  692.   {
  693.     ShowFPS ^= 1;
  694.  
  695.     if(!ShowFPS)
  696.       need_to_clear_bitmap = 1;
  697.   }
  698.  
  699.   if(showfpstemp)
  700.   {
  701.     showfpstemp--;
  702.  
  703.     if(!ShowFPS && !showfpstemp)
  704.       need_to_clear_bitmap = 1;
  705.   }
  706.  
  707.   if(ShowFPS || showfpstemp)
  708.   {
  709.     trueorientation = Machine->orientation;
  710.     Machine->orientation = ORIENTATION_DEFAULT;
  711.  
  712.     fps = VGetFPS(Video);
  713.     sprintf(buf," %3d%%(%3d/%d fps)",100*fps/Machine->drv->frames_per_second,fps,Machine->drv->frames_per_second);
  714.     l = strlen(buf);
  715.  
  716.     for (i = 0;i < l;i++)
  717.     {
  718.       drawgfx(Machine->scrbitmap,Machine->uifont,buf[i], DT_COLOR_WHITE, 0, 0,
  719.               Machine->uixmin + Machine->uiwidth - (l-i)*Machine->uifont->width,
  720.               Machine->uiymin, 0, TRANSPARENCY_NONE, 0);
  721.     }
  722.  
  723.     Machine->orientation = trueorientation;
  724.   }
  725.  
  726.   if(on_screen_display_timer > 0)
  727.   {
  728.     on_screen_display_timer -= (frameskip+1);
  729.  
  730.     if(on_screen_display_timer <= 0)
  731.     {
  732.       on_screen_display_timer = 0;
  733.       need_to_clear_bitmap    = 1;
  734.     }
  735.   }
  736.  
  737.   VSetFrameSkip(Video, frameskip);
  738.   VSetLimitSpeed(Video, throttle);
  739.  
  740.   if(DirectArray)
  741.   {
  742.     VSetDirectFrame(DirectArray);
  743.  
  744.     if(Config[CFG_DIRECTMODE] == CFGDM_DRAW)
  745.     {
  746.       if(DirectArray->Pixels)
  747.       {
  748.         h   = BitMap->height;
  749.         bpr   = DirectArray->BytesPerRow;
  750.         line  = DirectArray->Pixels + 8 + (8 * bpr);
  751.         lines = BitMap->line;
  752.   
  753.         for(i = 0; i < h; i++)
  754.         {
  755.           lines[i]    = line;
  756.           line      += bpr;
  757.         }
  758.       }
  759.       else
  760.         puts("PANIC! Didn't get direct pointer");
  761.     }
  762.     else
  763.     {
  764.       if(DirectArray->Pixels)
  765.       {
  766.         if(DirtyLines[0])
  767.         {
  768.           lines = BitMap->line;
  769.           h   = BitMap->height;
  770.           w   = BitMap->width >> 2;
  771.           pix   = (ULONG *) DirectArray->Pixels;
  772.           bpr   = DirectArray->BytesPerRow >> 2;
  773.           mod   = bpr - w;
  774.           new   = DirtyLines[0];
  775.           old   = DirtyLines[1];
  776.  
  777.           switch(Config[CFG_BUFFERING])
  778.           {
  779.             case CFGB_SINGLE:           
  780.               DirtyLines[0] = old;
  781.               DirtyLines[1] = new;
  782.  
  783.               for(i = 0; i < h; i++)
  784.               {
  785.                 if((*new++ | *old++))
  786.                 {
  787.                   src = (ULONG *) lines[i];
  788.               
  789.                   for(j = 0; j < w; j++)
  790.                     *pix++ = *src++;
  791.           
  792.                   pix += mod;
  793.                 }
  794.                 else
  795.                   pix += bpr;
  796.               }
  797.               
  798.               break;
  799.  
  800.             case CFGB_DOUBLE:             
  801.               new2 = DirtyLines[2];
  802.               old2 = DirtyLines[3];
  803.               
  804.               DirtyLines[0] = old2;
  805.               DirtyLines[1] = new2;
  806.               DirtyLines[2] = new;
  807.               DirtyLines[3] = old;
  808.               
  809.               for(i = 0; i < h; i++)
  810.               {
  811.                 if((*new++ | *new2++ | *old++ | *old2++))
  812.                 {
  813.                   src = (ULONG *) lines[i];
  814.               
  815.                   for(j = 0; j < w; j++)
  816.                     *pix++ = *src++;
  817.           
  818.                   pix += mod;
  819.                 }
  820.                 else
  821.                   pix += bpr;
  822.               }
  823.               
  824.               break;
  825.  
  826.             case CFGB_TRIPLE:
  827.               new2 = DirtyLines[2];
  828.               old2 = DirtyLines[3];
  829.               new3 = DirtyLines[4];
  830.               old3 = DirtyLines[5];
  831.               
  832.               DirtyLines[0] = old3;
  833.               DirtyLines[1] = new3;
  834.               DirtyLines[2] = new;
  835.               DirtyLines[3] = old;
  836.               DirtyLines[4] = new2;
  837.               DirtyLines[5] = old2;
  838.               
  839.               for(i = 0; i < h; i++)
  840.               {
  841.                 if((*new++ | *new2++ | *new3++ | *old++ | *old2++ | *old3++))
  842.                 {
  843.                   src = (ULONG *) lines[i];
  844.               
  845.                   for(j = 0; j < w; j++)
  846.                     *pix++ = *src++;
  847.           
  848.                   pix += mod;
  849.                 }
  850.                 else
  851.                   pix += bpr;
  852.               }
  853.               
  854.               break;
  855.           }
  856.  
  857.           memset(DirtyLines[0], 0, h);
  858.         }
  859.         else
  860.         {
  861.           lines = BitMap->line;
  862.           h   = BitMap->height;
  863.           w   = BitMap->width >> 2;
  864.           pix   = (ULONG *) DirectArray->Pixels;
  865.           bpr   = DirectArray->BytesPerRow >> 2;
  866.           mod   = bpr - w;
  867.           src   = (ULONG *) lines[0];
  868.           srcmod  = (((ULONG) BitMap->_private) >> 2) - w;
  869.  
  870.           for(i = 0; i < h; i++)
  871.           {
  872.             for(j = 0; j < w; j++)
  873.                 *pix++ = *src++;
  874.               
  875.             pix += mod;
  876.             src += srcmod;
  877.           }
  878.         }
  879.       }
  880.     }
  881.   }
  882.   else
  883.   {
  884.     PixelArray[CurrentArray]->BackgroundPen = Machine->pens[0];
  885.  
  886.     if(DirtyLines[0])
  887.     {
  888.       h = BitMap->height;
  889.       dst = PixelArray[CurrentArray]->DirtyLines + 8;
  890.       new = DirtyLines[0];
  891.       old = DirtyLines[1];
  892.  
  893.       switch(Config[CFG_BUFFERING])
  894.       {
  895.         case CFGB_SINGLE:           
  896.           DirtyLines[0] = old;
  897.           DirtyLines[1] = new;
  898.  
  899.           for(i = 0; i < h; i++)
  900.             *dst++ = *new++ | *old++;
  901.           
  902.           break;
  903.  
  904.         case CFGB_DOUBLE:             
  905.           new2 = DirtyLines[2];
  906.           old2 = DirtyLines[3];
  907.           
  908.           DirtyLines[0] = old2;
  909.           DirtyLines[1] = new2;
  910.           DirtyLines[2] = new;
  911.           DirtyLines[3] = old;
  912.           
  913.           for(i = 0; i < h; i++)
  914.             *dst++ = *new++ | *new2++ | *old++ | *old2++;
  915.           
  916.           break;
  917.  
  918.         case CFGB_TRIPLE:
  919.           new2 = DirtyLines[2];
  920.           old2 = DirtyLines[3];
  921.           new3 = DirtyLines[4];
  922.           old3 = DirtyLines[5];
  923.           
  924.           DirtyLines[0] = old3;
  925.           DirtyLines[1] = new3;
  926.           DirtyLines[2] = new;
  927.           DirtyLines[3] = old;
  928.           DirtyLines[4] = new2;
  929.           DirtyLines[5] = old2;
  930.           
  931.           for(i = 0; i < h; i++)
  932.             *dst++ = *new++ | *new2++ | *new3++ | *old++ | *old2++ | *old3++;
  933.           
  934.           break;
  935.       }
  936.  
  937.       VSetPixelFrame(PixelArray[CurrentArray]);
  938.  
  939.       memset(DirtyLines[0], 0, h);
  940.     }
  941.     else
  942.       VSetPixelFrame(PixelArray[CurrentArray]);
  943.   }
  944.  
  945.   frameskip = VGetFrameSkip(Video);
  946.  
  947.   if(need_to_clear_bitmap)
  948.     osd_clearbitmap(BitMap);
  949.  
  950.   input_update_counter = 0;
  951.   InputUpdate(FALSE);
  952.  
  953.   TRACE_LEAVE("osd_update_video_and_audio");
  954. }
  955.  
  956. void osd_modify_pen(int pen, unsigned char red, unsigned char green, unsigned char blue)
  957. {
  958.   TRACE_ENTER("osd_modify_pen");
  959.  
  960.   if(DirectArray)
  961.   {
  962.     DirectArray->Palette[pen][0]  = 1;
  963.     DirectArray->Palette[pen][1]  = red;
  964.     DirectArray->Palette[pen][2]  = green;
  965.     DirectArray->Palette[pen][3]  = blue;
  966.   }
  967.   else
  968.   {
  969.     PixelArray[CurrentArray]->Palette[pen][0] = 1;
  970.     PixelArray[CurrentArray]->Palette[pen][1] = red;
  971.     PixelArray[CurrentArray]->Palette[pen][2] = green;
  972.     PixelArray[CurrentArray]->Palette[pen][3] = blue;
  973.   }
  974.  
  975.   Palette[pen][0] = red;
  976.   Palette[pen][1] = green;
  977.   Palette[pen][2] = blue;
  978.  
  979.   TRACE_LEAVE("osd_modify_pen");
  980. }
  981.  
  982. void osd_get_pen(int pen, unsigned char *r, unsigned char *g, unsigned char *b)
  983. {
  984.   TRACE_ENTER("osd_get_pen");
  985.  
  986.   *r  = Palette[pen][0];
  987.   *g  = Palette[pen][1];
  988.   *b  = Palette[pen][2];
  989.  
  990.   TRACE_LEAVE("osd_get_pen");
  991. }
  992.  
  993. int osd_faccess (const char *filename, int filetype)
  994. {
  995.   return(1);
  996. }
  997.  
  998. int osd_fchecksum (const char *game, const char *filename, unsigned int *length, unsigned int *sum)
  999. {
  1000.   return(0);
  1001. }
  1002.  
  1003. void *osd_fopen(const char *gamename,const char *filename,int filetype,int write)
  1004. {
  1005.   struct File *file;
  1006.   char    *zip_name;
  1007.  
  1008.   file = NULL;
  1009.  
  1010.   if(!write)
  1011.   {
  1012.     if(filetype == OSD_FILETYPE_ROM)
  1013.       zip_name = ROMZipName;
  1014.     else if(filetype == OSD_FILETYPE_SAMPLE)
  1015.       zip_name = SampleZipName;
  1016.     else
  1017.       zip_name = NULL;
  1018.  
  1019.     if(zip_name && zip_name[0])
  1020.     {
  1021.       file = calloc(sizeof(struct File), 1);
  1022.           
  1023.       if(file)
  1024.       {
  1025.         if(!load_zipped_file(zip_name, filename, &file->Data, &file->Length))
  1026.         {
  1027.           file->Type  = FILETYPE_CUSTOM;
  1028.           file->CRC = crc32(0, file->Data, file->Length);
  1029.         }
  1030.         else
  1031.         {
  1032.           free(file);
  1033.           file = NULL;
  1034.         }
  1035.       }
  1036.     }
  1037.   }
  1038.  
  1039.   if(!file)
  1040.   {
  1041.     file = OpenFileType(gamename, filename, write ? MODE_NEWFILE : MODE_OLDFILE, filetype);
  1042.     
  1043.     if(file && (file->Type == FILETYPE_ZIP))
  1044.     {
  1045.       if(filetype == OSD_FILETYPE_ROM)
  1046.         zip_name = ROMZipName;
  1047.       else if(filetype == OSD_FILETYPE_SAMPLE)
  1048.         zip_name = SampleZipName;
  1049.       else
  1050.         zip_name = NULL;
  1051.  
  1052.       /* Cache the zip filename. */
  1053.       
  1054.       if(zip_name)
  1055.         strcpy(zip_name, file->Name);
  1056.  
  1057.       if(load_zipped_file(zip_name, filename, &file->Data, &file->Length))
  1058.       {
  1059.         file->Data = NULL;
  1060.         osd_fclose(file);
  1061.  
  1062.         return(NULL);
  1063.       }
  1064.  
  1065.       file->CRC = crc32(0, file->Data, file->Length);
  1066.     }
  1067.   }
  1068.  
  1069.   return((void *) file);
  1070. }
  1071.  
  1072. int osd_fread(void *file_handle, void *buffer, int length)
  1073. {
  1074.   struct File *file;
  1075.   LONG len;
  1076.  
  1077.   file = (struct File *) file_handle;
  1078.  
  1079.   switch(file->Type)
  1080.   {
  1081.     case FILETYPE_ZIP:
  1082.     case FILETYPE_CUSTOM:
  1083.       if(file->Data)
  1084.       {
  1085.         len = file->Length - file->Offset;
  1086.         
  1087.         if(len > length)
  1088.           len = length;
  1089.     
  1090.         memcpy(buffer, &file->Data[file->Offset], len);
  1091.     
  1092.         file->Offset += len;
  1093.         
  1094.         return(len);
  1095.       }
  1096.        
  1097.       break;
  1098.  
  1099.     case FILETYPE_NORMAL:
  1100.     case FILETYPE_TMP:
  1101.       len = ReadFile(file->File, buffer, length);
  1102.  
  1103.       return(len);
  1104.   }
  1105.  
  1106.   return(0);
  1107. }
  1108.  
  1109. int osd_fread_scatter(void *void_file_p, void *buffer_p, int length, int increment)
  1110. {
  1111.   struct File *file_p;
  1112.   UBYTE buf[4096];
  1113.   UBYTE *dst_p;
  1114.   UBYTE *src_p;
  1115.   int   remaining_len;
  1116.   int   len;
  1117.  
  1118.   file_p = (struct File *) void_file_p;
  1119.   dst_p  = buffer_p;
  1120.  
  1121.   switch(file_p->Type)
  1122.   {
  1123.     case FILETYPE_ZIP:
  1124.     case FILETYPE_CUSTOM:
  1125.       if(file_p->Data)
  1126.       {
  1127.         len = file_p->Length - file_p->Offset;
  1128.  
  1129.         if(len > length)
  1130.           len = length;
  1131.  
  1132.         length = len;
  1133.             
  1134.         src_p = &file_p->Data[file_p->Offset];
  1135.  
  1136.         while(len--)
  1137.         {
  1138.           *dst_p = *src_p++;
  1139.           
  1140.           dst_p += increment;
  1141.         }
  1142.     
  1143.         file_p->Offset += length;
  1144.  
  1145.         return(length);
  1146.       }
  1147.        
  1148.       break;
  1149.  
  1150.     case FILETYPE_NORMAL:
  1151.     case FILETYPE_TMP:
  1152.       remaining_len = length;
  1153.     
  1154.       while(remaining_len)
  1155.       {      
  1156.         if(remaining_len < sizeof(buf))
  1157.           len = remaining_len;
  1158.         else
  1159.           len = sizeof(buf);
  1160.  
  1161.         len = ReadFile(file_p->File, buf, len);
  1162.  
  1163.         if(len == 0)
  1164.           break;
  1165.  
  1166.         remaining_len -= len;
  1167.  
  1168.         src_p = buf;
  1169.         
  1170.         while(len--)
  1171.         {
  1172.           *dst_p = *src_p++;
  1173.           
  1174.           dst_p += increment;
  1175.         }
  1176.       }
  1177.       
  1178.       length = length - remaining_len;
  1179.       
  1180.       return(length);
  1181.       
  1182.       break;
  1183.   }
  1184.  
  1185.   return(0);
  1186. }
  1187.  
  1188. int osd_fread_swap(void *file_handle, void *buffer, int length)
  1189. {
  1190.     int i;
  1191.     unsigned char *buf;
  1192.     unsigned char temp;
  1193.     int res;
  1194.  
  1195.  
  1196.     res = osd_fread(file_handle,buffer,length);
  1197.  
  1198.     buf = buffer;
  1199.     for (i = 0;i < length;i+=2)
  1200.     {
  1201.         temp = buf[i];
  1202.         buf[i] = buf[i+1];
  1203.         buf[i+1] = temp;
  1204.     }
  1205.  
  1206.     return res;
  1207. }
  1208.  
  1209. int osd_fwrite(void *void_file_p, const void *buffer_p, int length)
  1210. {
  1211.   struct File *file_p;
  1212.   LONG rc;
  1213.  
  1214.   file_p = (struct File *) void_file_p;
  1215.  
  1216.   switch(file_p->Type)
  1217.   {
  1218.     case FILETYPE_ZIP:
  1219.     case FILETYPE_CUSTOM:
  1220.       return(-1);
  1221.  
  1222.     case FILETYPE_NORMAL:
  1223.     case FILETYPE_TMP:
  1224.       rc = WriteFile(file_p->File, (void *) buffer_p, length);
  1225.  
  1226.       if(rc > 0)
  1227.         return(rc);
  1228.   }
  1229.  
  1230.   return(0);
  1231. }
  1232.  
  1233. int osd_fwrite_swap(void *file,const void *buffer,int length)
  1234. {
  1235.     int i;
  1236.     unsigned char *buf;
  1237.     unsigned char temp;
  1238.     int res;
  1239.  
  1240.  
  1241.     buf = (unsigned char *)buffer;
  1242.     for (i = 0;i < length;i+=2)
  1243.     {
  1244.         temp = buf[i];
  1245.         buf[i] = buf[i+1];
  1246.         buf[i+1] = temp;
  1247.     }
  1248.  
  1249.     res = osd_fwrite(file,buffer,length);
  1250.  
  1251.     for (i = 0;i < length;i+=2)
  1252.     {
  1253.         temp = buf[i];
  1254.         buf[i] = buf[i+1];
  1255.         buf[i+1] = temp;
  1256.     }
  1257.  
  1258.     return res;
  1259. }
  1260.  
  1261. int osd_fseek(void *file, int position, int mode)
  1262. {
  1263.   LONG  rc = 0;
  1264.  
  1265.   if((((struct File *) file)->Type == FILETYPE_ZIP) || (((struct File *) file)->Type == FILETYPE_CUSTOM))
  1266.   {
  1267.     switch(mode)
  1268.     {
  1269.       case SEEK_SET:
  1270.         ((struct File *) file)->Offset = position;
  1271.         break;
  1272.       case SEEK_CUR:
  1273.         ((struct File *) file)->Offset += position;
  1274.         break;
  1275.       case SEEK_END:
  1276.         ((struct File *) file)->Offset = ((struct File *) file)->Length + position;
  1277.         break;
  1278.       default:
  1279.         return(-1);
  1280.     }
  1281.   }
  1282.   else
  1283.   {
  1284.     switch(mode)
  1285.     {
  1286.       case SEEK_SET:
  1287.         rc = SeekFile(((struct File *) file)->File, position, OFFSET_BEGINNING);
  1288.         break;
  1289.       case SEEK_CUR:
  1290.         rc = SeekFile(((struct File *) file)->File, position, OFFSET_CURRENT);
  1291.         break;
  1292.       case SEEK_END:
  1293.         rc = SeekFile(((struct File *) file)->File, position, OFFSET_END);
  1294.         break;
  1295.       default:
  1296.         return(-1);
  1297.     }
  1298.  
  1299. #ifdef POWERUP
  1300.     return(rc);
  1301. #else
  1302.     if(DOSBase->dl_lib.lib_Version > 37)
  1303.     {
  1304.       if(rc == -1)
  1305.         return(-1);
  1306.       else
  1307.         return(0);
  1308.     }
  1309.     else
  1310.     {
  1311.       if(IoErr())
  1312.         return(-1);
  1313.       else
  1314.         return(0);
  1315.     }
  1316. #endif
  1317.   }
  1318.  
  1319.   return(rc);
  1320. }
  1321.  
  1322. void osd_fclose(void *file)
  1323. {
  1324.   if(((((struct File *) file)->Type == FILETYPE_ZIP) || (((struct File *) file)->Type == FILETYPE_CUSTOM)) && ((struct File *) file)->Data)
  1325.     free(((struct File *) file)->Data);
  1326.   
  1327.   if(((struct File *) file)->Type == FILETYPE_CUSTOM)
  1328.     free(file);
  1329.   else
  1330.     CloseFile((struct File *) file);
  1331. }
  1332.  
  1333. void osd_led_w(int led,int on)
  1334. {
  1335. }
  1336.  
  1337. static int map_key(int key)
  1338. {
  1339.   switch(key)
  1340.   {
  1341.     case OSD_KEY_CANCEL:
  1342.       return(OSD_KEY_ESC);
  1343.  
  1344.     case OSD_KEY_RESET_MACHINE:
  1345.       return(OSD_KEY_F3);
  1346.  
  1347.     case OSD_KEY_SHOW_GFX:
  1348.       return(OSD_KEY_F4);
  1349.  
  1350.     case OSD_KEY_CHEAT_TOGGLE:
  1351.       return(OSD_KEY_F5);
  1352.  
  1353.     case OSD_KEY_SHOW_FPS:
  1354.       return(OSD_KEY_F7);
  1355.  
  1356.     case OSD_KEY_FRAMESKIP_INC:
  1357.       return(OSD_KEY_F9);
  1358.  
  1359.     case OSD_KEY_THROTTLE:
  1360.       return(OSD_KEY_F10);
  1361.  
  1362.     case OSD_KEY_CONFIGURE:
  1363.       return(OSD_KEY_TAB);
  1364.  
  1365.     case OSD_KEY_ON_SCREEN_DISPLAY:
  1366.       return(OSD_KEY_TILDE);
  1367.  
  1368.     case OSD_KEY_PAUSE:
  1369.     case OSD_KEY_UNPAUSE:
  1370.       return(OSD_KEY_P);
  1371.  
  1372.     case OSD_KEY_UI_SELECT:
  1373.       return(OSD_KEY_ENTER);
  1374.  
  1375.     case OSD_KEY_UI_LEFT:
  1376.       return(OSD_KEY_LEFT);
  1377.  
  1378.     case OSD_KEY_UI_RIGHT:
  1379.       return(OSD_KEY_RIGHT);
  1380.  
  1381.     case OSD_KEY_UI_UP:
  1382.       return(OSD_KEY_UP);
  1383.  
  1384.     case OSD_KEY_UI_DOWN:
  1385.       return(OSD_KEY_DOWN);
  1386.  
  1387.     default:
  1388.       return(key);
  1389.   }
  1390. }
  1391.  
  1392. int osd_key_invalid(int keycode)
  1393. {
  1394.     switch(keycode)
  1395.     {
  1396.         case OSD_KEY_ESC:
  1397.         case OSD_KEY_F3:
  1398.         case OSD_KEY_F4:
  1399.     case OSD_KEY_F7:
  1400.         case OSD_KEY_F8:
  1401.         case OSD_KEY_F10:
  1402.         case OSD_KEY_TAB:
  1403.         case OSD_KEY_TILDE:
  1404.         case OSD_KEY_P:
  1405.       return(1);
  1406.  
  1407.     default:
  1408.       return(0);
  1409.   }
  1410. }
  1411.  
  1412. const char *osd_key_name(int keycode)
  1413. {
  1414.     static const char *keynames[] =
  1415.     {
  1416.         "ESC", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "MINUS", "EQUAL", "BKSPACE",
  1417.         "TAB", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "OPBRACE", "CLBRACE", "ENTER",
  1418.         "LCTRL", "A", "S", "D", "F", "G", "H", "J", "K", "L", "COLON", "QUOTE", "TILDE",
  1419.         "LSHIFT", "Error", "Z", "X", "C", "V", "B", "N", "M", "COMMA", ".", "SLASH", "RSHIFT",
  1420.         "*", "ALT", "SPACE", "CAPSLOCK", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10",
  1421.         "NUMLOCK", "SCRLOCK", "HOME", "UP", "PGUP", "MINUS PAD",
  1422.         "LEFT", "5 PAD", "RIGHT", "PLUS PAD", "END", "DOWN",
  1423.         "PGDN", "INS", "DEL", "RCTRL", "ALTGR", "Error",
  1424.         "F11", "F12", "Error", "Error",
  1425.         "Error", "Error", "Error", "Error", "Error",
  1426.         "Error", "Error", "Error", "Error", "Error",
  1427.         "1 PAD", "2 PAD", "3 PAD", "4 PAD", "Error",
  1428.         "6 PAD", "7 PAD", "8 PAD", "9 PAD", "0 PAD",
  1429.         ". PAD", "= PAD", "/ PAD", "* PAD", "ENTER PAD",
  1430.         "Error", "Error", "Error", "Error", "Error",
  1431.     "Error", "Error", "PAUSE",
  1432.   };
  1433.  
  1434.     if(keycode && keycode <= OSD_MAX_KEY)
  1435.     return(keynames[keycode-1]);
  1436.     else
  1437.     return("None");
  1438. }
  1439.  
  1440. int osd_key_pressed(int key)
  1441. {
  1442.   if(!Keys)
  1443.     return(0);
  1444.  
  1445. #ifndef POWERUP
  1446.   /* To prevent the m68k version from being stuck in a waiting for
  1447.    * key loop. */
  1448.  
  1449.   input_update_counter++;
  1450.   
  1451.   if(input_update_counter > 1000)
  1452.   {
  1453.     input_update_counter = 0;
  1454.     InputUpdate(FALSE);
  1455.   }
  1456. #endif
  1457.  
  1458.   if(key == OSD_KEY_ANY)
  1459.     return(osd_read_key_immediate() != OSD_KEY_NONE);
  1460.  
  1461.   key = map_key(key);
  1462.  
  1463.   if((key < OSD_MAX_KEY) && Keys[key])
  1464.     return(1);
  1465.   
  1466.   return(0);
  1467. }
  1468.  
  1469. int osd_key_pressed_memory(int key)
  1470. {
  1471. #ifndef POWERUP
  1472.   /* To prevent the m68k version from being stuck in a waiting for
  1473.    * key loop. */
  1474.  
  1475.   input_update_counter++;
  1476.   
  1477.   if(input_update_counter > 1000)
  1478.   {
  1479.     input_update_counter = 0;
  1480.     InputUpdate(FALSE);
  1481.   }
  1482. #endif
  1483.  
  1484.   if(key == OSD_KEY_ANY)
  1485.     return(osd_read_key_immediate() != OSD_KEY_NONE);
  1486.  
  1487.   key = map_key(key);
  1488.  
  1489.   if(key < OSD_MAX_KEY)
  1490.   {
  1491.     if(Keys[key] == 1)
  1492.     {
  1493.       Keys[key] = 2;
  1494.  
  1495.       return(1);
  1496.     }
  1497.   }
  1498.   
  1499.   return(0);
  1500. }
  1501.  
  1502. int osd_key_pressed_memory_repeat(int key, int speed)
  1503. {
  1504.   static int counter;
  1505.   static int keydelay;
  1506.  
  1507. #ifndef POWERUP
  1508.   /* To prevent the m68k version from being stuck in a waiting for
  1509.    * key loop. */
  1510.  
  1511.   input_update_counter++;
  1512.   
  1513.   if(input_update_counter > 1000)
  1514.   {
  1515.     input_update_counter = 0;
  1516.     InputUpdate(FALSE);
  1517.   }
  1518. #endif
  1519.  
  1520.   if(key == OSD_KEY_ANY)
  1521.     return(osd_read_key_immediate() != OSD_KEY_NONE);
  1522.  
  1523.   key = map_key(key);
  1524.  
  1525.   if(key < OSD_MAX_KEY)
  1526.   {
  1527.     if(Keys[key] == 1)
  1528.     {
  1529.       Keys[key] = 2;
  1530.  
  1531.             keydelay = 3;
  1532.       counter  = 0;
  1533.  
  1534.       return(1);
  1535.     }
  1536.  
  1537.     if((Keys[key] == 2)
  1538.     && (++counter > keydelay * speed * Machine->drv->frames_per_second / 60))
  1539.     {
  1540.             keydelay = 1;
  1541.       counter  = 0;
  1542.  
  1543.       return(1);
  1544.     }   
  1545.   }
  1546.   
  1547.   return(0);
  1548.  
  1549. }
  1550.  
  1551. int osd_read_key_immediate(void)
  1552. {
  1553.   int key;
  1554.  
  1555. #ifndef POWERUP
  1556.   /* To prevent the m68k version from being stuck in a waiting for
  1557.    * key loop. */
  1558.  
  1559.   input_update_counter++;
  1560.   
  1561.   if(input_update_counter > 1000)
  1562.   {
  1563.     input_update_counter = 0;
  1564.     InputUpdate(FALSE);
  1565.   }
  1566. #endif
  1567.  
  1568.   for(key = OSD_MAX_KEY; (key > OSD_KEY_NONE) && !Keys[key]; key--);
  1569.  
  1570.   if((key > OSD_KEY_NONE) && (Keys[key] == 1))
  1571.   {
  1572.     Keys[key] = 2;
  1573.  
  1574.     return(key);
  1575.   }
  1576.  
  1577.   return(OSD_KEY_NONE);
  1578. }
  1579.  
  1580. int osd_read_keyrepeat(void)
  1581. {
  1582.   int key;
  1583.  
  1584.   while((key = osd_read_key_immediate()) == OSD_KEY_NONE)
  1585.     InputUpdate(TRUE);
  1586.  
  1587.   return(key);
  1588. }
  1589.  
  1590. const char *osd_joy_name(int joycode)
  1591. {
  1592.     static const char *joynames[] = {
  1593.         "Left", "Right", "Up", "Down", "Button A",
  1594.         "Button B", "Button C", "Button D", "Button E", "Button F",
  1595.         "Button G", "Button H", "Button I", "Button J", "Any Button",
  1596.         "J2 Left", "J2 Right", "J2 Up", "J2 Down", "J2 Button A",
  1597.         "J2 Button B", "J2 Button C", "J2 Button D", "J2 Button E", "J2 Button F",
  1598.         "J2 Button G", "J2 Button H", "J2 Button I", "J2 Button J", "J2 Any Button",
  1599.         "J3 Left", "J3 Right", "J3 Up", "J3 Down", "J3 Button A",
  1600.         "J3 Button B", "J3 Button C", "J3 Button D", "J3 Button E", "J3 Button F",
  1601.         "J3 Button G", "J3 Button H", "J3 Button I", "J3 Button J", "J3 Any Button",
  1602.         "J4 Left", "J4 Right", "J4 Up", "J4 Down", "J4 Button A",
  1603.         "J4 Button B", "J4 Button C", "J4 Button D", "J4 Button E", "J4 Button F",
  1604.         "J4 Button G", "J4 Button H", "J4 Button I", "J4 Button J", "J4 Any Button"
  1605.     };
  1606.  
  1607.     if(joycode == 0)
  1608.     return("None");
  1609.     else if(joycode <= OSD_MAX_JOY)
  1610.     return(joynames[joycode-1]);
  1611.     else
  1612.     return("Unknown");
  1613. }
  1614.  
  1615. void osd_poll_joysticks(void)
  1616. {
  1617. }
  1618.  
  1619. int osd_joy_pressed(int joycode)
  1620. {
  1621.   if(Keys)
  1622.   {
  1623.     if(joycode < OSD_JOY2_LEFT)
  1624.     {
  1625.       switch(joycode)
  1626.       {
  1627.         case OSD_JOY_FIRE1:
  1628.           if(Port2->Type == IPT_MOUSE)
  1629.             return(Port2->Red);
  1630.  
  1631.           return(Port1->Red);
  1632.  
  1633.         case OSD_JOY_FIRE2:
  1634.           if(Port2->Type == IPT_MOUSE)
  1635.             return(Port2->Blue);
  1636.  
  1637.           return(Port1->Blue);
  1638.  
  1639.         case OSD_JOY_FIRE3:
  1640.           if(Port2->Type == IPT_MOUSE)
  1641.             return(Port2->Green);
  1642.  
  1643.           return(Port1->Green);
  1644.  
  1645.         case OSD_JOY_FIRE4:
  1646.           return(Port1->Yellow);
  1647.  
  1648.         case OSD_JOY_FIRE5:
  1649.           return(Port1->Forward);
  1650.  
  1651.         case OSD_JOY_FIRE6:
  1652.           return(Port1->Reverse);
  1653.  
  1654.         case OSD_JOY_FIRE7:
  1655.           return(Port1->Play);
  1656.  
  1657.         case OSD_JOY_FIRE:
  1658.           if(Port2->Type == IPT_MOUSE)
  1659.             return(Port2->Red | Port2->Blue | Port2->Green |
  1660.                    Port1->Red | Port1->Blue | Port1->Green | Port1->Yellow |
  1661.                    Port1->Forward | Port1->Reverse | Port1->Play);
  1662.  
  1663.           return(Port1->Red | Port1->Blue | Port1->Green | Port1->Yellow |
  1664.                  Port1->Forward | Port1->Reverse | Port1->Play);
  1665.         default:
  1666.           if((Port1->Type == IPT_JOYSTICK) || (Port1->Type == IPT_JOYPAD))
  1667.           {
  1668.             switch(joycode)
  1669.             {
  1670.               case OSD_JOY_LEFT:
  1671.                 return(Port1->Move.Joystick.Left);
  1672.  
  1673.               case OSD_JOY_RIGHT:
  1674.                 return(Port1->Move.Joystick.Right);
  1675.  
  1676.               case OSD_JOY_UP:
  1677.                 return(Port1->Move.Joystick.Up);
  1678.  
  1679.               case OSD_JOY_DOWN:
  1680.                 return(Port1->Move.Joystick.Down);
  1681.             }
  1682.           }
  1683.       }
  1684.     }
  1685.     else
  1686.     {
  1687.       switch(joycode)
  1688.       {
  1689.         case OSD_JOY2_FIRE1:
  1690.           return(Port2->Red);
  1691.  
  1692.         case OSD_JOY2_FIRE2:
  1693.           return(Port2->Blue);
  1694.  
  1695.         case OSD_JOY2_FIRE3:
  1696.           return(Port2->Green);
  1697.  
  1698.         case OSD_JOY2_FIRE4:
  1699.           return(Port2->Yellow);
  1700.  
  1701.         case OSD_JOY2_FIRE5:
  1702.           return(Port2->Forward);
  1703.  
  1704.         case OSD_JOY2_FIRE6:
  1705.           return(Port2->Reverse);
  1706.  
  1707.         case OSD_JOY2_FIRE7:
  1708.           return(Port2->Play);
  1709.  
  1710.         case OSD_JOY2_FIRE:
  1711.           return( Port2->Red | Port2->Blue | Port2->Green | Port2->Yellow
  1712.               | Port2->Forward | Port2->Reverse | Port2->Play);
  1713.  
  1714.         default:
  1715.           if((Port2->Type == IPT_JOYSTICK) || (Port2->Type == IPT_JOYPAD))
  1716.           {
  1717.             switch(joycode)
  1718.             {
  1719.               case OSD_JOY2_LEFT:
  1720.                 return(Port2->Move.Joystick.Left);
  1721.  
  1722.               case OSD_JOY2_RIGHT:
  1723.                 return(Port2->Move.Joystick.Right);
  1724.  
  1725.               case OSD_JOY2_UP:
  1726.                 return(Port2->Move.Joystick.Up);
  1727.  
  1728.               case OSD_JOY2_DOWN:
  1729.                 return(Port2->Move.Joystick.Down);
  1730.             }
  1731.           }
  1732.       }
  1733.     }
  1734.   }
  1735.  
  1736.   return(0);
  1737. }
  1738.  
  1739. void osd_trak_read(int player, int *deltax, int *deltay)
  1740. {
  1741.   if((player == 0) && (Port2->Type == IPT_MOUSE))
  1742.   {
  1743.     *deltax           = Port2->Move.Mouse.MouseX;
  1744.     Port2->Move.Mouse.MouseX  = 0;
  1745.     *deltay           = Port2->Move.Mouse.MouseY;
  1746.     Port2->Move.Mouse.MouseY  = 0;
  1747.   }
  1748.   else
  1749.   {
  1750.     *deltax = 0;
  1751.     *deltay = 0;
  1752.   }
  1753. }
  1754.  
  1755. void osd_analogjoy_read(int player, int *analog_x, int *analog_y)
  1756. {
  1757.   *analog_x = 0;
  1758.   *analog_y = 0;
  1759. }
  1760.  
  1761. void osd_play_sample(int channel,signed char *data,int len,int freq,int volume,int loop)
  1762. {
  1763.   if(ChannelArray[0] && (channel < AUDIO_CHANNELS))
  1764.   {
  1765. #ifdef POWERUP
  1766.     if(!ChannelArray[1])
  1767.       return;
  1768. #endif
  1769.     if(len > 0)
  1770.     {
  1771. #ifdef POWERUP
  1772.       if(len > AUDIO_BUFFER_LENGTH)
  1773.       {
  1774.         len = AUDIO_BUFFER_LENGTH;
  1775.         printf("audio clipping\n");
  1776.       }
  1777.  
  1778.       memcpy(ChannelArray[CurrentArray]->Channels[channel].Buffer, data, len);
  1779.  
  1780.       data = ChannelArray[CurrentArray]->Channels[channel].Buffer;
  1781. #endif
  1782.       APlaySample(ChannelArray[CurrentArray], channel, freq, volume * 100 / 255, len, data, loop);
  1783.     }
  1784.     else if(len < 0)
  1785.     {
  1786.       APlaySound(ChannelArray[CurrentArray], channel, freq, volume * 100 / 255, -len, loop);
  1787.     }
  1788.   }
  1789. }
  1790.  
  1791. void osd_play_sample_16(int channel,signed short *data,int len,int freq,int volume,int loop)
  1792. {
  1793. }
  1794.  
  1795. void osd_play_streamed_sample(int channel,signed char *data,int len,int freq,int volume, int pan)
  1796. {
  1797.   osd_play_sample(channel, data, len, freq, volume, TRUE);
  1798. }
  1799.  
  1800. void osd_play_streamed_sample_16(int channel,signed short *data,int len,int freq,int volume, int pan)
  1801. {
  1802. }
  1803.  
  1804. void osd_adjust_sample(int channel,int freq,int volume)
  1805. {
  1806.   if(ChannelArray[0] && (channel < AUDIO_CHANNELS))
  1807.   {
  1808. #ifdef POWERUP
  1809.     if(!ChannelArray[1])
  1810.       return;
  1811. #endif
  1812.     ASetFrequency(ChannelArray[CurrentArray], channel, freq);
  1813.     ASetVolume(ChannelArray[CurrentArray], channel, volume * 100 / 255);
  1814.   }
  1815. }
  1816.  
  1817. void osd_stop_sample(int channel)
  1818. {
  1819.   if(ChannelArray[0])
  1820.   {
  1821. #ifdef POWERUP
  1822.     if(!ChannelArray[1])
  1823.       return;
  1824. #endif
  1825.     AStopChannel(ChannelArray[CurrentArray], channel);
  1826.   }
  1827. }
  1828.  
  1829. void osd_restart_sample(int channel)
  1830. {
  1831.   if(ChannelArray[0])
  1832.   {
  1833. #ifdef POWERUP
  1834.     if(!ChannelArray[1])
  1835.       return;
  1836. #endif
  1837.     ARestartChannel(ChannelArray[CurrentArray], channel);
  1838.   }
  1839. }
  1840.  
  1841. int osd_get_sample_status(int channel)
  1842. {
  1843.   return(-1);
  1844. }
  1845.  
  1846. void osd_ym2203_write(int n, int r, int v)
  1847. {
  1848. }
  1849.  
  1850. void osd_ym2203_update(void)
  1851. {
  1852. }
  1853.  
  1854. int osd_ym3812_status(void)
  1855. {
  1856.   return(0);
  1857. }
  1858.  
  1859. int osd_ym3812_read(void)
  1860. {
  1861.   return(0);
  1862. }
  1863.  
  1864. void osd_ym3812_control(int reg)
  1865. {
  1866. }
  1867.  
  1868. void osd_ym3812_write(int data)
  1869. {
  1870. }
  1871.  
  1872. void osd_set_mastervolume(int attenuation)
  1873. {
  1874.     float volume;
  1875.  
  1876.     Attenuation = attenuation;
  1877.  
  1878.      volume = 256.0;    /* range is 0-256 */
  1879.  
  1880.     while(attenuation++ < 0)
  1881.         volume /= 1.122018454;    /* = (10 ^ (1/20)) = 1dB */
  1882.  
  1883.   MasterVolume = volume;
  1884.  
  1885.   if(ChannelArray[0])
  1886.   {
  1887. #ifdef POWERUP
  1888.     if(!ChannelArray[1])
  1889.       return;
  1890. #endif
  1891.     ASetMasterVolume(ChannelArray[CurrentArray], MasterVolume);
  1892.   }
  1893. }
  1894.  
  1895. int osd_get_mastervolume(void)
  1896. {
  1897.   return(Attenuation);
  1898. }
  1899.  
  1900. void osd_sound_enable(int enable)
  1901. {
  1902. #ifdef POWERUP
  1903.   if(ChannelArray[0] && ChannelArray[1])
  1904. #else
  1905.   if(ChannelArray[0])
  1906. #endif
  1907.   {
  1908.     if(enable)
  1909.     {
  1910.       ASetMasterVolume(ChannelArray[CurrentArray], MasterVolume);
  1911.     }
  1912.     else
  1913.     {
  1914.       ASetMasterVolume(ChannelArray[CurrentArray], 0);
  1915.     }
  1916.   }
  1917. }
  1918.  
  1919. struct GameSamples *readsamples(const char **samplenames,const char *basename)
  1920. {
  1921.   struct MameSample *mame_sample;
  1922.   struct GameSamples  *samples;
  1923.   struct ASound   *sound;
  1924.   LONG        skipfirst;
  1925.   LONG        i;
  1926.  
  1927. #ifdef POWERUP
  1928.     if(!ChannelArray[1])
  1929.       return(NULL);
  1930. #endif
  1931.  
  1932.   if(ChannelArray[0])
  1933.   {
  1934.     skipfirst = 0;
  1935.  
  1936.     if(samplenames && samplenames[0])
  1937.     {
  1938.       if(samplenames[0][0] == '*')
  1939.         skipfirst = 1;
  1940.  
  1941.       i = 0;
  1942.  
  1943.       while(samplenames[i+skipfirst])
  1944.         i++;
  1945.  
  1946.       if((samples = malloc(sizeof(struct GameSamples) + (i-1)*sizeof(struct GameSample))))
  1947.       {
  1948.         samples->total = i;
  1949.  
  1950.         for(i = 0; i < samples->total; i++)
  1951.           samples->sample[i] = 0;
  1952.  
  1953.         for(i = 0; i < samples->total; i++)
  1954.         {
  1955.           struct File *file;
  1956.  
  1957.           if(samplenames[i+skipfirst][0])
  1958.           {
  1959.             file = osd_fopen(basename,samplenames[i+skipfirst],OSD_FILETYPE_SAMPLE,0);
  1960.             
  1961.             if(!file && skipfirst)
  1962.               file = osd_fopen(samplenames[0]+1,samplenames[i+skipfirst],OSD_FILETYPE_SAMPLE,0);
  1963.  
  1964.             if(file)
  1965.             {
  1966.               if((file->Type == FILETYPE_ZIP) || (file->Type == FILETYPE_CUSTOM))
  1967.               {
  1968.                 mame_sample = (struct MameSample *) file->Data;
  1969.                 
  1970.                 if((mame_sample->ID == MAKE_ID('M','A','M','E')) && mame_sample->Length)
  1971.                 {
  1972.                   sound = ALoadSound(Audio, mame_sample->Data,
  1973.                                 mame_sample->Resolution,
  1974.                                 INTELULONG(mame_sample->Length),
  1975.                                 INTELULONG(mame_sample->Frequency),
  1976.                                 mame_sample->Volume);
  1977.                 }
  1978.                 else
  1979.                   sound = NULL;
  1980.               }
  1981.               else
  1982.                 sound = AReadSound(Audio, file->File);
  1983.  
  1984.               if(sound)
  1985.               {
  1986.                 samples->sample[i] = malloc(sizeof(struct GameSample));
  1987.                 
  1988.                 if(samples->sample[i]);
  1989.                 {
  1990.                   samples->sample[i]->length    = -sound->Sound;
  1991.                   samples->sample[i]->volume    = sound->Volume;
  1992.                   samples->sample[i]->smpfreq   = sound->Frequency;
  1993.                   samples->sample[i]->resolution  = 8;
  1994.                 }
  1995.  
  1996.               }
  1997.  
  1998.               osd_fclose(file);
  1999.             }
  2000.           }
  2001.         }
  2002.  
  2003.         return(samples);
  2004.       }
  2005.     }
  2006.   }
  2007.   
  2008.   return(NULL);
  2009. }
  2010.  
  2011. int osd_skip_this_frame(void)
  2012. {
  2013.   if(FrameCounter >= NoFrameSkipCount)
  2014.   {
  2015.     if(FrameCounter < (NoFrameSkipCount + frameskip))
  2016.       return(1);
  2017.   }
  2018.  
  2019.   return(0);
  2020. }
  2021.  
  2022. #ifdef MESS
  2023. #if 0
  2024. extern int CurrentVolume;
  2025.  
  2026. int osd_handle_event(void)
  2027. {
  2028. static  int showvoltemp = 0;
  2029.  
  2030.         /* if the user pressed ESC, stop the emulation */
  2031.         if (osd_key_pressed(UI_KEY_ESCAPE))
  2032.                 return 1;
  2033.  
  2034.         if (osd_key_pressed(UI_KEY_DEC_VOLUME) && osd_key_pressed(OSD_KEY_LSHIFT) == 0)
  2035.         {
  2036.                 /* decrease volume */
  2037.                 if (CurrentVolume > 0) CurrentVolume--;
  2038.                 osd_set_mastervolume(CurrentVolume);
  2039.                 showvoltemp = 50;
  2040.         }
  2041.  
  2042.         if (osd_key_pressed(UI_KEY_INC_VOLUME) && osd_key_pressed(OSD_KEY_LSHIFT) == 0)
  2043.         {
  2044.                 /* increase volume */
  2045.                 if (CurrentVolume < 100) CurrentVolume++;
  2046.                 osd_set_mastervolume(CurrentVolume);
  2047.                 showvoltemp = 50;
  2048.         }                                          /* MAURY_END: new options */
  2049.  
  2050.         if (osd_key_pressed(UI_KEY_PAUSE)) /* pause the game */
  2051.         {
  2052.                 struct DisplayText dt[2];
  2053.                 int count = 0;
  2054.  
  2055.  
  2056.                 dt[0].text = "PAUSED";
  2057.                 dt[0].color = DT_COLOR_RED;
  2058.                 dt[0].x = (Machine->uiwidth - Machine->uifont->width * strlen(dt[0].text)) / 2;
  2059.                 dt[0].y = (Machine->uiheight - Machine->uifont->height) / 2;
  2060.                 dt[1].text = 0;
  2061.  
  2062.                 osd_set_mastervolume(0);
  2063.  
  2064.                 while (osd_key_pressed(UI_KEY_PAUSE))
  2065.                         osd_update_audio();     /* give time to the sound hardware to apply the volume change */
  2066.  
  2067.                 while (osd_key_pressed(UI_KEY_PAUSE) == 0 && osd_key_pressed(UI_KEY_ESCAPE) == 0)
  2068.                 {
  2069.                         if (osd_key_pressed(UI_KEY_MENU)) setup_menu(); /* call the configuration menu */
  2070.  
  2071.                         osd_clearbitmap(Machine->scrbitmap);
  2072.  
  2073.                         (*Machine->drv->vh_update)(Machine->scrbitmap, 1);  /* redraw screen */
  2074.  
  2075.                         if (count < Machine->drv->frames_per_second / 2)
  2076.                                 displaytext(dt,0);      /* make PAUSED blink */
  2077.                         else
  2078.                                 osd_update_display();
  2079.  
  2080.                         count = (count + 1) % (Machine->drv->frames_per_second / 1);
  2081.                 }
  2082.  
  2083.                 while (osd_key_pressed(UI_KEY_ESCAPE));   /* wait for jey release */
  2084.                 while (osd_key_pressed(UI_KEY_PAUSE));     /* ditto */
  2085.  
  2086.                 osd_set_mastervolume(CurrentVolume);
  2087.                 osd_clearbitmap(Machine->scrbitmap);
  2088.         }
  2089.  
  2090.         /* if the user pressed TAB, go to the setup menu */
  2091.         if (osd_key_pressed(UI_KEY_MENU))
  2092.         {
  2093.                 osd_set_mastervolume(0);
  2094.  
  2095.                 while (osd_key_pressed(UI_KEY_MENU))
  2096.                         osd_update_audio();     /* give time to the sound hardware to apply the volume change */
  2097.  
  2098.                 if (setup_menu()) return 1;
  2099.  
  2100.                 osd_set_mastervolume(CurrentVolume);
  2101.         }
  2102.  
  2103.         /* if the user pressed F4, show the character set */
  2104.         if (osd_key_pressed(UI_KEY_CHARSET))
  2105.         {
  2106.                 osd_set_mastervolume(0);
  2107.  
  2108.                 while (osd_key_pressed(UI_KEY_CHARSET))
  2109.                         osd_update_audio();     /* give time to the sound hardware to apply the volume change */
  2110.  
  2111.                 if (showcharset()) return 1;
  2112.  
  2113.                 osd_set_mastervolume(CurrentVolume);
  2114.         }
  2115.  
  2116.         if (showvoltemp)
  2117.         {
  2118.                 showvoltemp--;
  2119.                 if (!showvoltemp)
  2120.                 {
  2121.                         osd_clearbitmap(Machine->scrbitmap);
  2122.                 }
  2123.                 else
  2124.                 {                     /* volume-meter */
  2125.                 int trueorientation;
  2126.                 int i,x;
  2127.                 char volstr[25];
  2128.                         trueorientation = Machine->orientation;
  2129.                         Machine->orientation = ORIENTATION_DEFAULT;
  2130.  
  2131.                         x = (Machine->uiwidth - 24*Machine->uifont->width)/2;
  2132.                         strcpy(volstr,"                      ");
  2133.                         for (i = 0;i < (CurrentVolume/5);i++) volstr[i+1] = '\x15';
  2134.  
  2135.                         drawgfx(Machine->scrbitmap,Machine->uifont,16,DT_COLOR_RED,0,0,x,Machine->drv->screen_height/2,0,TRANSPARENCY_NONE,0);
  2136.                         drawgfx(Machine->scrbitmap,Machine->uifont,17,DT_COLOR_RED,0,0,x+23*Machine->uifont->width,Machine->drv->screen_height/2,0,TRANSPARENCY_NONE,0);
  2137.                         for (i = 0;i < 22;i++)
  2138.                             drawgfx(Machine->scrbitmap,Machine->uifont,(unsigned int)volstr[i],DT_COLOR_WHITE,
  2139.                                         0,0,x+(i+1)*Machine->uifont->width+Machine->uixmin,Machine->uiheight/2+Machine->uiymin,0,TRANSPARENCY_NONE,0);
  2140.  
  2141.                         Machine->orientation = trueorientation;
  2142.                 }
  2143.         }
  2144.  
  2145.         return 0;
  2146. }
  2147. #endif
  2148.  
  2149. int osd_fdc_init(void)
  2150. {
  2151.   return(1);
  2152. }
  2153.  
  2154. void osd_fdc_exit(void)
  2155. {
  2156. }
  2157.  
  2158. void osd_fdc_motors(unsigned char unit)
  2159. {
  2160. }
  2161.  
  2162. void osd_fdc_density(unsigned char unit, unsigned char density, unsigned char tracks, unsigned char spt, unsigned char eot, unsigned char secl)
  2163. {
  2164. }
  2165.  
  2166. void osd_fdc_interrupt(int param)
  2167. {
  2168. }
  2169.  
  2170. unsigned char osd_fdc_recal(unsigned char *track)
  2171. {
  2172.   return(0);
  2173. }
  2174.  
  2175. unsigned char osd_fdc_seek(unsigned char t, unsigned char *track)
  2176. {
  2177.   return(0);
  2178. }
  2179.  
  2180. unsigned char osd_fdc_step(int dir, unsigned char *track)
  2181. {
  2182.   return(0);
  2183. }
  2184.  
  2185. unsigned char osd_fdc_format(unsigned char t, unsigned char h, unsigned char spt, unsigned char *fmt)
  2186. {
  2187.   return(0);
  2188. }
  2189.  
  2190. unsigned char osd_fdc_put_sector(unsigned char track, unsigned char side, unsigned char head, unsigned char sector, unsigned char *buff, unsigned char ddam)
  2191. {
  2192.   return(0);
  2193. }
  2194.  
  2195. unsigned char osd_fdc_get_sector(unsigned char track, unsigned char side, unsigned char head, unsigned char sector, unsigned char *buff)
  2196. {
  2197.   return(0);
  2198. }
  2199. #endif
  2200.  
  2201. void osd_on_screen_display(const char *text,int percentage)
  2202. {
  2203. #if 0
  2204.   int i,j,start,avail,cutoff;
  2205.  
  2206.  
  2207.   on_screen_display_timer = 2*Machine->drv->frames_per_second;
  2208.  
  2209.   strcpy(on_screen_display_text,text);
  2210.   strcat(on_screen_display_text," ");
  2211.  
  2212.   start = strlen(on_screen_display_text);
  2213.   avail = (gfx_display_columns / Machine->uifont->width) * 9 / 10;
  2214.   avail -= start;
  2215.   cutoff = 8 * avail * percentage / 100;
  2216.   for (i = 0;i < avail;i++)
  2217.   {
  2218.     if (8 * i >= cutoff)
  2219.       on_screen_display_text[start + i] = ' ';
  2220.     else if (8 * (i + 1) <= cutoff)
  2221.       on_screen_display_text[start + i] = 8;
  2222.     else
  2223.       on_screen_display_text[start + i] = cutoff - 8 * i;
  2224.   }
  2225.   on_screen_display_text[start + avail] = 0;  /* nul terminate */
  2226. #endif
  2227. }
  2228.  
  2229. int osd_fsize(void *file)
  2230. {
  2231.   if((((struct File *) file)->Type == FILETYPE_ZIP) || (((struct File *) file)->Type == FILETYPE_CUSTOM))
  2232.     return(((struct File *) file)->Length);
  2233.  
  2234.   return(0);
  2235. }
  2236.  
  2237. unsigned int osd_fcrc(void *file)
  2238. {
  2239.   if((((struct File *) file)->Type == FILETYPE_ZIP) || (((struct File *) file)->Type == FILETYPE_CUSTOM))
  2240.     return(((struct File *) file)->CRC);
  2241.  
  2242.   return(0);
  2243. }
  2244.  
  2245. void osd_set_gamma(float gamma)
  2246. {
  2247. }
  2248.  
  2249. float osd_get_gamma(void)
  2250. {
  2251.   return(1.0);
  2252. }
  2253.  
  2254. void osd_set_brightness(int brightness)
  2255. {
  2256. }
  2257.  
  2258. int osd_get_brightness(void)
  2259. {
  2260.   return(100);
  2261. }
  2262.  
  2263. void osd_profiler(int type)
  2264. {
  2265. }
  2266.  
  2267. void osd_save_snapshot(void)
  2268. {
  2269. }
  2270.  
  2271. int osd_joystick_needs_calibration (void)
  2272. {
  2273.   return(0);
  2274. }
  2275.  
  2276.  
  2277. void osd_joystick_start_calibration (void)
  2278. {
  2279. }
  2280.  
  2281. char *osd_joystick_calibrate_next (void)
  2282. {
  2283.   return(NULL);
  2284. }
  2285.  
  2286. void osd_joystick_calibrate (void)
  2287. {
  2288. }
  2289.  
  2290. void osd_joystick_end_calibration (void)
  2291. {
  2292. }
  2293.  
  2294. int osd_display_loading_rom_message(const char *name,int current,int total)
  2295. {
  2296.   return(0);
  2297. }
  2298.